<%--
  Created by IntelliJ IDEA.
  User: houxianghua
  Date: 2015/7/21
  Time: 8:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="">
  <meta name="author" content="">
  <title></title>
  <%@include file="/WEB-INF/jsp/component/commonHead.jsp" %>
  <%@include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
  <style>
    .text-center{
      text-align:center;
    }
  </style>
</head>
<%--<body onresize="reSizeParentIframe()" onload="reSizeParentIframe();">--%>
<body>
  <div class="row">
    <div class="col-lg-12">
      <h1 class="page-header">专家结论管理</h1>
    </div>
    <!-- /.col-lg-12 -->
  </div>
  <!-- /.row -->
  <div class="row">
    <div class="col-lg-12">
      <div class="panel panel-default">
        <div class="panel-heading">
            结论名称:<input type="text" id="conclusionName" name="conclusionName"/>
            <button id="query" class="mk_butt" >查询</button>
            <%--<button id="query" type="button" class="btn btn-outline btn-success">查询</button>--%>
        </div>
        <!-- /.panel-heading -->
        <div class="panel-body">
          <div class="dataTable_wrapper">
            <table id="example" class="table table-striped table-bordered table-hover" width="100%">
              <thead>
              <tr align="left">
                <th width="5%"><input id="all_id" type="checkbox"></th>
                <th width="14%">项目名称</th>
                <th width="8%">标准</th>
                <th width="12%">结论名称</th>
                <th width="61%">结论</th>
              </tr>
              </thead>
              <tbody>
              </tbody>
            </table>
          </div>
        </div>
        <!-- /.panel-body -->
      </div>
      <!-- /.panel -->
    </div>
    <!-- /.col-lg-12 -->
  </div>

  <script>
    var table;
    function initTable() {
      table = $("#example").DataTable({
        "dom": "<'row'<'col-xs-2'l><'#mytool.col-xs-10'><'col-xs-6'f>r>" +
        "t" +
        "<'row'<'col-xs-6'i><'col-xs-6'p>>",
        "bFilter": false,//去掉搜索框
        "bAutoWidth": false, //自适应宽度
        "sPaginationType" : "full_numbers",
//                "bDestroy" : true,
//              "asStripeClasses": [ 'strip1', 'strip2', 'strip3' ],//设置斑马条（奇偶行）的css class
        "ordering": false,//是否允许Datatables开启排序
        "bProcessing" : true,
        "bServerSide" : true,
        "sAjaxSource" : "${URL_ADM_CONCLUSION_SEARCH}",
        "sAjaxDataProp": "dataList",//查询后，返回的集合
        "fnServerData": function ( sSource, aoData, fnCallback ) {  //查询条件
          aoData.push(
                  { "name": "conclusionName", "value": $("#conclusionName").val() }
          );
          $.ajax( {
            "dataType": 'json',
            "url": sSource,
            "type":'post',
            "data": aoData,
            "success": fnCallback
          } );

        },
        "aoColumns" : [ {
          "targets": -1,
          "data": null,
          "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
            $(nTd).html('' +
                    '&nbsp;&nbsp;<input name="id" value="'+oData.id+'" type="checkbox" onClick="isCheckedAll()">' +
                    '');
          }
        }, {
          "mDataProp" : "testItemName"
        }, {
          "mDataProp" : "conclusionKind",
          "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
            var levelName = "";
            if(sData==1){
              levelName = "超高";
            }else if(sData==2){
              levelName = "超低";
            }
            $(nTd).html(levelName);
          }
        }, {
          "mDataProp" : "conclusionName"
        }, {
          "mDataProp" : "conclusionInfo",
            "sDefaultContent" : "",
            "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                if (sData.length > 100) {
                    $(nTd).html(sData.substring(0, 100) + "......");
                    $(nTd).attr({title:sData});
                } else {
                    $(nTd).html(sData);
                }
            }
        }
        ],
        "oLanguage" : {
          "sProcessing" : "正在加载中......",
          "sLengthMenu" : "每页显示 _MENU_ 条记录",
          "sZeroRecords" : "没有数据！",
          "sEmptyTable" : "无数据存在！",
          "sInfo" : "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",
          "sInfoEmpty" : "显示0到0条记录",
          "sInfoFiltered" : "数据表中共为 _MAX_ 条记录",
          //"sSearch" : "搜索",
          "oPaginate" : {
            "sFirst" : "首页",
            "sPrevious" : "上一页",
            "sNext" : "下一页",
            "sLast" : "末页"
          }
        },
        initComplete: function () {
            <shiro:hasPermission name="+testProjectItemConclusion+8">
            $("#mytool").append('<button id="delete_butt" type="button" class="btn btn-outline btn-success" style="float:right;">删除</button>');
            $("#delete_butt").on("click", toDelete);
            </shiro:hasPermission>
            <shiro:hasPermission name="+testProjectItemConclusion+4">
            $("#mytool").append('<button id="update_butt" type="button" class="btn btn-outline btn-success" style="float:right;">修改</button>');
            $("#update_butt").on("click", toUpdate);
            </shiro:hasPermission>
            <shiro:hasPermission name="+testProjectItemConclusion+2">
            $("#mytool").append('<button id="add_butt" type="button" class="btn btn-outline btn-success" style="float:right;">新增</button>');
            $("#add_butt").on("click", toAdd);
            </shiro:hasPermission>
            <shiro:hasPermission name="+testProjectItemConclusion">
            $("#mytool").append('<button id="export_butt" type="button" class="btn btn-outline btn-success" style="float:right;">导出</button>');
            $("#export_butt").on("click", toExport);
            </shiro:hasPermission>
            <shiro:hasPermission name="+testProjectItemConclusion+2">
            $("#mytool").append('<button id="import_butt" type="button" class="btn btn-outline btn-success" style="float:right;">导入</button>');
            $("#import_butt").on("click", toImport);
            </shiro:hasPermission>
        }
      });
    }

    //新增
    function toAdd(){
      $("#addIframe").attr("src", "${URL_ADM_CONCLUSION_TOADD}");//新增地址
      $('#addModal').modal({ show: true, backdrop: 'static' });

      var width = 800;
      var height = 600;
      var mycss={"width":width+"px","height":height+"px","top":(($(window).height()-height)/2>0?($(window).height()-height)/2:0)+"px"};
      $('#addModal .modal-dialog').css(mycss).find('.modal-content').css({height: '100%',width: '100%'}).find('.modal-body').css({height: '75%' });
      window.parent.showModelIframe('${URL_ADM_CONCLUSION_TOADD}',"新增专家结论",800,850);
    }

    //修改
    function toUpdate(){
      var checkedArray = getCheckedArray();
      if(checkedArray.length!=1){
        top.bootbox.dialog({
          message: "请选中一项数据",
          buttons: {
            OK: {
              label: "确定",
              className: "btn-primary"
            }
          }
        });
        return false;
      }
      window.parent.showModelIframe('${URL_ADM_CONCLUSION_TOUPDATE}?id=' +checkedArray[0],"修改专家结论",800,850);
    }

    //删除
    function toDelete(){
      var checkedArray = getCheckedArray();
      var ids = "";
      if(checkedArray.length==0){
        top.bootbox.dialog({
          message: "请选中至少一项数据",
          buttons: {
            OK: {
              label: "确定",
              className: "btn-primary"
            }
          }
        });
        return false;
      }else{
        for(var i=0; i<checkedArray.length;i++){
          ids += checkedArray[i]+",";
        }
        ids = ids.substring(0,ids.length-1);
      }
      top.bootbox.dialog({
        message: "确定删除此项？",
        buttons: {
          OK: {
            label: "确定",
            className: "btn-primary",
            callback: function () {
              $.ajax({
                url:'${URL_ADM_CONCLUSION_DELETES}',//删除地址
                type:'post',
                data:{ids:ids},
                async : false, //默认为true 异步
                error:function(){
                  alert('error');
                },
                success:function(data){
                  refreshTable();
                }
              });
            }
          },
          Cancel: {
            label: "取消",
            className: "btn-default"
          }
        }
      });
    }

    //多选按钮
    $("#all_id").click(function(){
      if(this.checked){
        $("input[name='id']").each(function(){
          $(this)[0].checked = true;
        });
      }else{
        $("input[name='id']").each(function(){
          $(this)[0].checked = false;
        });
      }
    });

    //判断是否已经全选
    function isCheckedAll(){
      var isCheckAll = true;
      $("input[name='id']").each(function(){
        if(!this.checked){
          isCheckAll = false;
        }
      });
      if(isCheckAll){
        $("#all_id")[0].checked = true;
      }else{
        $("#all_id")[0].checked = false;
      }
    }

    function getCheckedArray(){
      var checkedArray = [];
      $("input[name='id']").each(function(){
        if(this.checked){
          checkedArray.push(this.value);
        }
      });
      return checkedArray;
    }

//    //新增提交  调用子级页面新增方法
//    $("#submit_add").click(function(){
//      document.getElementById('addIframe').contentWindow.doAdd();
//    });
//
//    //修改提交  调用子级页面修改方法
//    $("#submit_update").click(function(){
//      document.getElementById('updateIframe').contentWindow.doUpdate();
//    });

    //关闭弹出框
    function closeModal(flag){
      $('#'+flag+"Modal").modal('hide');
      refreshTable();
    }

    //只关闭弹出框，不刷新
    function simpleCloseModal(flag){
      $('#'+flag+"Modal").modal('hide');
    }

    //查询
    $("#query").click(function() {
      refreshTable();
    });

    //导入
    function toImport() {
        window.parent.showModelIframe('${URL_ADM_CONCLUSION_TOIMPORT}',"导入Excel",800,400);
    }

    //导出
    function toExport() {
        window.parent.showModelIframe('${URL_ADM_CONCLUSION_TOEXPORT}',"导出Excel",800,400);
    }

    //刷新table数据
    function refreshTable(){
      table.ajax.reload();
      //重置全选按钮
      $("#all_id")[0].checked = false;
    }

    $(document).ready(function() {
      initTable();
    });
  </script>
</body>
</html>